import logging

import requests


# 创建登录模块的类
from ihrmApiTest import app


class LoginApi:

    # 登录接口
    def login(self, json_dict=None):
        url = app.BASE_HOST + "/api/sys/login"
        res = requests.post(url=url, json=json_dict)
        # 获取字典类型的响应体数据
        res_dict = res.json()
        logging.info("登录接口返回的响应体数据：{}".format(res_dict))
        return res

    # 获取token
    def get_token(self, json_dict):
        # 1.调用封装登录接口的方法，获取响应数据
        res = self.login(json_dict)
        # 2.提取token信息，完成拼接
        token_value = res.json().get("data")
        token = "Bearer" + " " + token_value
        logging.info("获取的token：{}".format(token))
        # 3.返回完整的token
        return token


if __name__ == '__main__':
    json_dict = {"mobile": "13800000001", "password": "123456"}
    print(LoginApi().get_token(json_dict))
